using System;
using System.Collections.Generic;
using System.Xml;

namespace Studio.Game.GameBox
{

    public static class Keywords<T>
    {
        private static KeyTree<T> _KeyTree;
        
        /// <summary>
        /// The only constructor
        /// </summary>
        static Keywords()
        {
            // Build dictionary by keywords version
            Dictionary<string, T> Words = new Dictionary<string, T>();
            foreach (T Word in Enum.GetValues(typeof(T)))
                Words.Add(Word.ToString(), Word);          
            // Build key tree
            _KeyTree = new KeyTree<T>(Words);
        }

        /// <summary>
        /// Keyword recognization
        /// </summary>
        public static bool Recognize(string Word, ref T Keyword)
        {
            return _KeyTree.Recognize(Word, ref Keyword);
        }

        /// <summary>
        /// Override keyword recognization, return INVALID if recognization failed.
        /// </summary>
        public static T Recognize(string Word)
        {
            T Keyword = default(T);
            _KeyTree.Recognize(Word, ref Keyword);
            return Keyword;
        }
    }
}
